<template>
  <div class="valuate-container">
    <div class="title-row">
      <span class="title-item">您的问题是否已经解决了？</span>
      <div class="iconfont icon-cancelquxiao" @click="close"></div>
    </div>
    <div class="dispose-wrap">
      <div class="dispose-item" :class="{ bgc: dealState === 1 }" @click="onDeal">
        <div class="iconfont icon-dui" :class="{ 'deal-color': dealState === 1 }"></div>
        <span class="deal-text">已解决</span>
      </div>
      <div class="dispose-item" :class="{ bgc: dealState === 2 }" @click="onDisDeal">
        <div class="iconfont icon-fujianguanbi" :class="{ 'disdeal-color': dealState === 2 }"></div>
        <span class="deal-text">未解决</span>
      </div>
    </div>
    <div class="title-row row-two">
      <span class="title-item">请对本次服务评价</span>
    </div>
    <div class="dispose-rate">
      <span class="rate-label">总体</span>
      <van-rate v-model="form.opinionRating" :size="23" color="#ffd21e" void-icon="star" void-color="#eee" />
    </div>
    <div class="dispose-input">
      <textarea class="uni-input" v-model.trim="form.feedback" maxlength="50" placeholder="您的反馈会督促我们做得更好(最多50个字)" />
    </div>
    <div class="submit">
      <span class="submit-btn" @click="onSubmit" :class="{ opacity: enable }">提交</span>
    </div>
  </div>
</template>

<script>
import { Rate } from 'vant'
import { comment } from '@/api/index.js'
export default {
  components: {
    [Rate.name]: Rate,
  },
  data() {
    return {
      form: {
        isTrue: '',
        opinionRating: null,
        feedback: '',
      },
      dealState: 0,
      enable: false,
    }
  },
  props: {
    commentInfo: {
      type: Object,
      default: () => {
        return {}
      },
    },
  },
  watch: {
    form: {
      handler(val) {
        const { isTrue, opinionRating, feedback } = val
        if (isTrue !== '' || opinionRating || feedback) {
          this.enable = true
        } else {
          this.enable = false
        }
      },
      deep: true,
    },
  },
  methods: {
    onDeal() {
      this.form.isTrue = 1
      this.dealState = 1
    },
    onDisDeal() {
      this.form.isTrue = 0
      this.dealState = 2
    },
    onSubmit() {
      if (!this.commentInfo.meetingId || !this.enable) {
        return
      }
      const params = {
        ...this.form,
        ...this.commentInfo,
      }
      comment(params).then(() => {
        this.form.closeType = true
        this.$emit('commentClose', this.form)
        this.$toast('评价成功！')
      })
    },
    close() {
      this.form.closeType = false
      this.$emit('commentClose', this.form)
    },
  },
}
</script>

<style lang="scss" scoped>
@import '@/assets/font/iconfont.scss';
.bgc {
  background: linear-gradient(269deg, #fecb7d 0%, #ffddab 100%) !important;
}
.deal-color {
  color: #ff9a58 !important;
}
.disdeal-color {
  color: #ff5952 !important;
}
.valuate-container {
  padding: 15px;
  font-size: 15px;
  color: #72819b;
  background-color: #fff;
  box-sizing: border-box;
}
.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .title-item {
    font-weight: 600;
  }
  .icon-cancelquxiao {
    font-size: 15px;
    color: #acacac;
  }
}

.dispose-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  .dispose-item {
    width: 165px;
    height: 30px;
    line-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f4f9;
    border-radius: 4px;
  }
  .icon-dui,
  .icon-fujianguanbi {
    font-size: 23px;
    color: #b2baca;
  }
}

.row-two {
  margin-top: 20px;
}

.dispose-rate {
  margin-top: 10px;
  display: flex;
  align-items: center;
  .rate-label {
    margin-right: 5px;
  }
}

.dispose-input {
  margin-top: 20px;
  .uni-input {
	width: 100%;
	border: none;
    background: #f1f4f9;
    border-radius: 4px;
    height: 60px;
    padding: 10px 15px;
    font-size: 13px;
    color: #999999;
  }
}

.submit {
  margin-top: 15px;
  text-align: center;
  &-btn {
    display: inline-block;
    text-align: center;
    color: #fff;
    width: 244px;
    height: 40px;
    line-height: 40px;
    background: linear-gradient(90deg, #3861fe 0%, #489bfe 100%);
    box-shadow: 0 4px 6px -2px rgba(59, 162, 255, 0.34);
    border-radius: 22px;
    opacity: 0.3;
  }
  & .opacity {
    opacity: 1;
  }
}
</style>
